package com.sophialex.health.record.common.bind.swt.annotations;

import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.validation.IValidator;

public class BindingConfig {
	IValidator afterGetOfUi = null;
	IValidator beforeSetOfUi = null;

	IValidator afterGetOfModel = null;

	IValidator beforeSetOfModel = null;

	IConverter converterOfUi = null;
	IConverter converterOfModel = null;

	

	public BindingConfig setAfterGetOfUi(IValidator afterGetOfUi) {
		this.afterGetOfUi = afterGetOfUi;
		return this;
	}

	public BindingConfig setBeforeSetOfUi(IValidator beforeSetOfUi) {
		this.beforeSetOfUi = beforeSetOfUi;
		return this;
	}

	public BindingConfig setAfterGetOfModel(IValidator afterGetOfModel) {
		this.afterGetOfModel = afterGetOfModel;
		return this;
	}

	public BindingConfig setBeforeSetOfModel(IValidator beforeSetOfModel) {
		this.beforeSetOfModel = beforeSetOfModel;
		return this;
	}

	public BindingConfig setConvertorOfUi(IConverter convertorOfUi) {
		this.converterOfUi = convertorOfUi;
		return this;
	}

	public BindingConfig setConvertorOfModel(IConverter convertorOfModel) {
		this.converterOfModel = convertorOfModel;
		return this;
	}

	public IValidator getAfterGetOfUi() {
		return afterGetOfUi;
	}

	public IValidator getBeforeSetOfUi() {
		return beforeSetOfUi;
	}

	public IValidator getAfterGetOfModel() {
		return afterGetOfModel;
	}

	public IValidator getBeforeSetOfModel() {
		return beforeSetOfModel;
	}

	public IConverter getConvertorOfUi() {
		return converterOfUi;
	}

	public IConverter getConvertorOfModel() {
		return converterOfModel;
	}
	public UpdateValueStrategy updateValueStrategyOfUi(){
		UpdateValueStrategy u = null;
		if(getAfterGetOfUi()!=null){
			u = new UpdateValueStrategy();
			u.setAfterGetValidator(getAfterGetOfUi());
		}
		if(getBeforeSetOfUi()!=null){
			u = (u==null?new UpdateValueStrategy():u);
			u.setBeforeSetValidator(getBeforeSetOfUi());
		}
		if(getConvertorOfUi()!=null){
			u = (u==null?new UpdateValueStrategy():u);
			u.setConverter(getConvertorOfUi());
		}
		return u;	
	}
	public UpdateValueStrategy updateValueStrategyOfModel(){
		UpdateValueStrategy u = null;
		if(getAfterGetOfModel()!=null){
			u = new UpdateValueStrategy();
			u.setAfterGetValidator(getAfterGetOfModel());
		}
		if(getBeforeSetOfModel()!=null){
			u = (u==null?new UpdateValueStrategy():u);
			u.setBeforeSetValidator(getBeforeSetOfModel());
		}
		if(getConvertorOfModel()!=null){
			u = (u==null?new UpdateValueStrategy():u);
			u.setConverter(getConvertorOfModel());
		}
		return u;	
	}
}
